﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Data.MyDbContext;
using DAL;

namespace WebIndex1.Controllers
{
    public class HomeController : Controller
    {
        private readonly IUnitOfRepositories _repositories = null;
        public HomeController(IUnitOfRepositories repositories)
        {
            _repositories = repositories;
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";


            string name = Request.LogonUserIdentity.Name;
            return View(_repositories.CategoryRepo.GetAll());
        }

        public void ChangeMode(string mode)
        {
            if (mode == "edit")
            {
                HttpCookie myCookie = new HttpCookie("mode");
                myCookie.Value = "edit";
                myCookie.Expires = DateTime.Now.AddDays(1d);
                Response.Cookies.Add(myCookie);
            }
            else
            {
                Response.Cookies["mode"].Value = "";
            }
            Response.Redirect("/home/main");

           
        }

        //public ActionResult Index

        public ActionResult Main()
        {
            ViewBag.Message = "This is main page.";

            return View(_repositories.CategoryRepo.GetAll());
        }

        //public ActionResult About()
        //{
        //    ViewBag.Message = "Your app description page.";

        //    return View();
        //}

        //public ActionResult Contact()
        //{
        //    ViewBag.Message = "Your contact page.";

        //    return View();
        //}

        //protected override void Dispose(bool disposing)
        //{
        //    db.Dispose();
        //    base.Dispose(disposing);
        //}
    }
}
